package mobi.hami.huapin.dao;

import java.util.List;

import mobi.hami.huapin.daobase.CrudMapper;
import mobi.hami.huapin.dto.SKUForUserDTO;
import mobi.hami.huapin.model.Product;
import mobi.hami.huapin.model.ProductShowAttribute;
import mobi.hami.huapin.model.Productsku;
import mobi.hami.huapin.model.ProductskuExample;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

@Repository
public interface ProductskuMapper extends CrudMapper<Productsku> {
@Select("<script>" +
        "select *from Productsku"
        + "<where>"
        + "<if test='productid >0'>  AND productid = #{productid}</if>"
        + "<if test='skuname!=null'>  AND skuname  like    CONCAT('%',#{skuname},'%') </if>"
        + "<if test='id>0'>  AND id  = #{id}</if>"
        + "<if test='deleted>=0 and deleted!=null'>  AND deleted  = #{deleted}</if>"
        + "</where>"
        +" order by id desc"
        +"</script>")
List<Productsku> getProductSkuList(Productsku productsku);

    @Update("update Productsku set deleted=#{deleted} where id=#{id}")
    int   deleteSku(Productsku productsku);

    /**
     * 根据spu 返回所有
     * @param spuid
     * @return
     */
    @Select("select  id,skuname,productid,show_price,group_price,price,barcode from productsku where productid = #{spuid} and deleted =0 and published =1")
    List<SKUForUserDTO> getProductSkuListBySpuID(long spuid);


    /**
     * 用户前端查询
     * @param ids
     * @return
     */
    @Select("SELECT id,skuname,barcode from productsku where id in (${ids})  order by id asc ")
    public List<Productsku> getListForPrint(@Param("ids")String ids);
}